<%= form_for CrmFormPresenter.new(widget, request, controller), url: scrivito_path(widget.obj), html: { class: "form-horizontal"} do |form| %>
  <% if widget.subject %>
    <%= form.hidden_field(:title, value: widget.subject) %>
  <% end %>

  <%= form.hidden_field(:widget_id, value: widget.id) %>

  <% widget.attributes.each do |name, options| %>
    <% CrmFormPresenter.send(:attr_accessor, name.to_sym) %>
    <%= render "crm_form_widget/crm_#{options["attribute_type"]}", form: form, name: name, options: options, label: nil %>
  <% end %>

  <% widget.dynamic_attributes.each do |attribute| %>
    <% CrmFormPresenter.send(:attr_accessor, attribute.field_name.to_sym) %>
    <%= render "crm_form_widget/crm_#{attribute.type}", form: form, name: attribute.field_name, options: attribute.options || {}, label: attribute.label %>
  <% end %>

  <div class="form-group last">
    <label class="control-label col-sm-3" for="crm_form_presenter_email">Email</label>
    <div class="col-sm-9">
      <input class="form-control" type="text" name="crm_form_presenter[email]" id="crm_form_presenter_email">
    </div>
  </div>
  <%= form.submit widget.submit_button, class: "btn btn-primary pull-right" %>

<% end %>